package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.msg.rest.service.IMpAutoMessageService;
import com.ibeeking.found.msg.service.common.param.MpAutoMessageParam;
import com.ibeeking.found.msg.service.common.query.MpMessagePageQuery;
import com.ibeeking.found.msg.service.common.vo.MpAutoMessagePageVO;
import com.ibeeking.found.msg.service.common.vo.MpAutoMessageVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自动消息回复配置
 * @ClassName WxmpAutoMessageController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-02-05 19:11
 **/
@RestController
@RequestMapping("/b/wxMp/autoReplyMsg/v1")
public class WxMpAutoMessageController {


    @Resource
    private IMpAutoMessageService mpAutoMessageServiceImpl;


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "自动消息回复分页查询")
    @PostMapping(value = "/pageList")
    public Page<MpAutoMessagePageVO> pageList(@RequestBody @Validated MpMessagePageQuery query) {
        return mpAutoMessageServiceImpl.pageList(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "自动消息回复添加")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) MpAutoMessageParam param) {
        return mpAutoMessageServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "自动消息回复修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser,@RequestBody @Validated(BaseValidationGroup.Update.class) MpAutoMessageParam param) {
        param.setModifyBy(currentUser.getId());
        return mpAutoMessageServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "展示详情")
    @GetMapping(value = "/view/{id}")
    public MpAutoMessageVO view(@PathVariable("id") Long id) {
        return mpAutoMessageServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改发布状态")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return mpAutoMessageServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除自动回复")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return mpAutoMessageServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从公众号同步自动回复消息")
    @PostMapping(value = "/syncAutoReplayMessageFromWx/{type}")
    public Boolean syncAutoReplayMessageFromWx(@PathVariable("type") Integer type) {
        return mpAutoMessageServiceImpl.syncAutoReplayMessageFromWx(type);
    }

}
